<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>排序算法</title>
	</head>
	<body>
	</body>
    <script type="text/javascript">
        // 排序算法
		function quickSort(arr) {

            if(arr.length<=1) {
                return arr;
            }

            let leftArr = [];
            let rightArr = [];
            let q = arr[0];
            for(let i = 1,l=arr.length; i<l; i++) {
                if(arr[i]>q) {
                    rightArr.push(arr[i]);
                }else{
                    leftArr.push(arr[i]);
                }
            }
            
            return [].concat(quickSort(leftArr),[q],quickSort(rightArr));
        }
        

        // 冒泡排序算法
        function bubbleSort(arr) {  
            for(let i = 0,l=arr.length;i<l-1;i++) {
                for(let j = i+1;j<l;j++) { 
                if(arr[i]>arr[j]) {
                        let tem = arr[i];
                        arr[i] = arr[j];
                        arr[j] = tem;
                    }
                }
            }
            return arr;
        }

        const arry = [1,2,35,1,26,23,4,2]

        console.log(quickSort(arry))

        console.log(bubbleSort(arry))

	</script>
</html>
